import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import _ClickAwayListener from "@mui/material/ClickAwayListener";
import _Fade from "@mui/material/Fade";
import React, { useEffect, useMemo } from "react";
import styles from "./index.module.less";
import { useSafeState } from "ahooks";
import classNames from "classnames";
import Ona from "./ona";
import Nfts from "./nfts";
import toast from "../../compoents/toast";
import kingsInstance from "../../instance";
import { useDispatch, useSelector } from "react-redux";
import { EVENT } from "../../enums";
import useRouter from "../../hooks/useRouter";
import { useTranslation } from "react-i18next";
import { isDomesticVersion } from "../../config";
import { LocalKeyMap } from "../../local";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var SignOutBtn = function(props) {
    var _useSafeState = _sliced_to_array(useSafeState(false), 2), open = _useSafeState[0], setOpen = _useSafeState[1];
    var userInfo = useSelector(function(state) {
        return state.app.userInfo;
    });
    var dispatch = useDispatch();
    var signOut = function() {
        dispatch.app.deleteUserInfo();
        dispatch.app.PUSH("/login");
        kingsInstance.emit(EVENT.close);
    };
    var signOutClick = function() {
        // setOpen(false);
        var destroy = toast.confirm({
            title: /*#__PURE__*/ _jsx("div", {
                children: "Are you sure you want to sign out?"
            }),
            onConfirm: function() {
                destroy();
                signOut();
            }
        }).destroy;
    };
    return /*#__PURE__*/ _jsx(_ClickAwayListener, {
        onClickAway: function() {
            setOpen(false);
        },
        children: /*#__PURE__*/ _jsxs("div", {
            className: styles["p_r"],
            children: [
                props.trigger && /*#__PURE__*/ React.cloneElement(props.trigger, {
                    onClick: function(e) {
                        var _props_trigger, _props_trigger_props, _props_trigger_props_onClick;
                        setOpen(!open);
                        (_props_trigger = props.trigger) === null || _props_trigger === void 0 ? void 0 : (_props_trigger_props = _props_trigger.props) === null || _props_trigger_props === void 0 ? void 0 : (_props_trigger_props_onClick = _props_trigger_props.onClick) === null || _props_trigger_props_onClick === void 0 ? void 0 : _props_trigger_props_onClick.call(_props_trigger_props, e);
                    }
                }),
                /*#__PURE__*/ _jsx(_Fade, {
                    in: open,
                    unmountOnExit: true,
                    mountOnEnter: true,
                    children: /*#__PURE__*/ _jsxs("div", {
                        className: classNames(styles["sign_out"], !open ? styles["sign_close"] : ""),
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: classNames(styles.nav_item, styles.user_item),
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: styles.img,
                                        children: /*#__PURE__*/ _jsx("img", {
                                            src: require("../../assets/icons/account.svg")
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("span", {
                                        children: userInfo.email ? userInfo.email : userInfo.phone
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.nav_item,
                                onClick: function() {
                                    window.open("http://noa.nfkings.com");
                                },
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: styles.img,
                                        children: /*#__PURE__*/ _jsx("img", {
                                            src: require("../../assets/icons/info.svg")
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("span", {
                                        children: "About ONA"
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.nav_item,
                                onClick: function() {
                                    dispatch.app.PUSH("/changePassword");
                                },
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: styles.img,
                                        children: /*#__PURE__*/ _jsx("img", {
                                            src: require("../../assets/icons/pwd.svg")
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("span", {
                                        children: "Change password"
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                onClick: signOutClick,
                                className: styles.nav_item,
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: styles.img,
                                        children: /*#__PURE__*/ _jsx("img", {
                                            src: require("../../assets/icons/signOut.svg")
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("span", {
                                        children: "Sign out"
                                    })
                                ]
                            })
                        ]
                    })
                })
            ]
        })
    });
};
function Home() {
    var _routerInfo_location, _routerInfo_location_query;
    var routerInfo = useRouter();
    var _useSafeState = _sliced_to_array(useSafeState(isDomesticVersion ? "NFTS" : (routerInfo === null || routerInfo === void 0 ? void 0 : (_routerInfo_location = routerInfo.location) === null || _routerInfo_location === void 0 ? void 0 : (_routerInfo_location_query = _routerInfo_location.query) === null || _routerInfo_location_query === void 0 ? void 0 : _routerInfo_location_query.currentType) || "TOKENS"), 2), type = _useSafeState[0], setType = _useSafeState[1];
    var tabs = isDomesticVersion ? [
        "NFTS",
        "TOKENS"
    ] : [
        "TOKENS",
        "NFTS"
    ];
    // const chainNft = useSelector((Rstate: RootState) => Rstate.app.chainNft);
    var _useSelector = useSelector(function(state) {
        return {
            theme: state.app.theme,
            userInfo: state.app.userInfo,
            notice: state.app.notice
        };
    }), theme = _useSelector.theme, userInfo = _useSelector.userInfo, notice = _useSelector.notice;
    var dispatch = useDispatch();
    var t = useTranslation().t;
    var body = useMemo(function() {
        if (type === "TOKENS") return /*#__PURE__*/ _jsx(Ona, {});
        if (type === "NFTS") return /*#__PURE__*/ _jsx(Nfts, {});
        return null;
    }, [
        type
    ]);
    var getAnnouncementNum = function() {
        return notice.totalAnnouncementCount - notice.readAnnouncementCount;
    };
    var getMessageNum = function() {
        return notice.totalMessageCount - notice.readMessageCount;
    };
    var handleNotice = function() {
        var nabIndex = 0;
        if (getMessageNum() === 0 && getAnnouncementNum() > 0) {
            nabIndex = 1;
        }
        dispatch.app.PUSH({
            path: "/notifications",
            query: {
                tabIndex: nabIndex
            }
        });
    };
    var initNotice = function() {
        dispatch.app.initNotice();
    };
    var noticeNum = getAnnouncementNum() + getMessageNum();
    useEffect(function() {
        initNotice();
    }, []);
    return /*#__PURE__*/ _jsxs("div", {
        className: styles.content,
        children: [
            /*#__PURE__*/ _jsxs("header", {
                className: styles.header,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: styles.menu,
                        onClick: function() {
                            dispatch.app.PUSH("/personalInformation");
                        },
                        children: /*#__PURE__*/ _jsx("img", {
                            // src={matchTheme(theme, {
                            //   light: require("@/assets/icons/light/menu.svg"),
                            //   dark: require("@/assets/icons/dark/menu.svg"),
                            // })}
                            src: userInfo.avatarLink
                        })
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: styles.nav,
                        children: tabs.map(function(tab, i) {
                            return /*#__PURE__*/ _jsx("div", {
                                onClick: function() {
                                    if (isDomesticVersion) {
                                        toast.createToast({
                                            message: t(LocalKeyMap.functionDisabled)
                                        });
                                        return;
                                    }
                                    dispatch.app.PUSH({
                                        path: "/home",
                                        query: {
                                            currentType: tab
                                        }
                                    });
                                    setType(tab);
                                },
                                className: classNames(styles.item, type === tab ? styles.active : ""),
                                children: /*#__PURE__*/ _jsx("div", {
                                    children: t(tab.toLowerCase())
                                })
                            }, i);
                        })
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: styles.notice,
                        onClick: function() {
                            handleNotice();
                        },
                        children: /*#__PURE__*/ _jsxs("div", {
                            className: styles.noticeBox,
                            children: [
                                noticeNum > 0 && /*#__PURE__*/ _jsx("strong", {
                                    children: noticeNum > 99 ? "99+" : noticeNum
                                }),
                                /*#__PURE__*/ _jsx("img", {
                                    src: require("../../assets/icons/icon-email.svg"),
                                    alt: ""
                                })
                            ]
                        })
                    })
                ]
            }),
            /*#__PURE__*/ _jsx("div", {
                className: styles.page,
                children: body
            })
        ]
    });
}
export default Home;

 //# sourceMappingURL=home.js.map